import 'package:flutter/material.dart';

//有状态组件,StatefulWidget
class MyApp3 extends StatefulWidget {
  const MyApp3({super.key});

  @override
  State<MyApp3> createState() => _MyApp3State();
}

class _MyApp3State extends State<MyApp3> {
  String name = '小白';
  num age = 2;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //导航条
      appBar: AppBar(
        title: const Text(
          '下午不睡觉',
          style: TextStyle(color: Colors.white, fontSize: 20),
        ),
        backgroundColor: Colors.pink,
        centerTitle: true,
      ),
      body: Center(
        child: Text(
          '姓名:$name,年龄:$age岁',
          style: TextStyle(
            fontSize: 40,
            color: const Color.fromARGB(255, 8, 161, 204),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          //setState所包裹的动态数据可以让视图同步更新
          setState(() {
            age = age + 1;
          });
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
